package utils

// MergeMapI32I64 合并map
func MergeMapI32I64(m1, m2 map[int32]int64) map[int32]int64 {
	rs := make(map[int32]int64)
	for k, v := range m1 {
		rs[k] = v
	}
	for k, v := range m2 {
		rs[k] += v
	}
	return rs
}

// MergeMapI64I64 合并map
func MergeMapI64I64(m1, m2 map[int64]int64) map[int64]int64 {
	rs := make(map[int64]int64)
	for k, v := range m1 {
		rs[k] = v
	}
	for k, v := range m2 {
		rs[k] += v
	}
	return rs
}

// MergeMapI32I64Positive 合并map,value为正数
func MergeMapI32I64Positive(m1, m2 map[int32]int64) map[int32]int64 {
	rs := make(map[int32]int64)
	for k, v := range m1 {
		rs[k] = v
	}
	for k, v := range m2 {
		rs[k] += v
	}
	for k, v := range rs {
		if v < 0 {
			rs[k] = 0
		}
	}
	return rs
}

// MergeMapI64I64Positive 合并map,value为正数
func MergeMapI64I64Positive(m1, m2 map[int64]int64) map[int64]int64 {
	rs := make(map[int64]int64)
	for k, v := range m1 {
		rs[k] = v
	}
	for k, v := range m2 {
		rs[k] += v
	}
	for k, v := range rs {
		if v < 0 {
			rs[k] = 0
		}
	}
	return rs
}
